package com.text.textRecognition.controller;

import com.text.textRecognition.service.PayService;
import com.text.textRecognition.service.TextRecognitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: zxw
 * Date: 2023-04-24
 * Time: 15:11
 * Description:
 */
@Slf4j
@Controller
@RequestMapping(value = "/textRecognition")
@Api(tags = {"文字识别"})
public class TextRecognitionController {

    @Autowired
    private TextRecognitionService textRecognitionService;

    @Autowired
    PayService payService;

    @PostMapping("getRecognizeResult")
    @ApiOperation(value = "获取文字识别结果")
    public String getRecognizeResult(@RequestParam("file") MultipartFile file, HttpServletResponse response,
                                     HttpServletRequest request) {
        String content = textRecognitionService.getRecognizeResult(file, response);
        request.setAttribute("content", content);
        return "print";
    }

    @ResponseBody
    @PostMapping("toPay")
    public Object String(HttpServletRequest request) throws Exception {
        Integer number = Integer.valueOf(request.getParameter("number"));
        return payService.pay(1, number);
    }

}
